package com.example.a2205douyin.live;

import androidx.lifecycle.MutableLiveData;

import com.example.a2205douyin.baseMVVM.model.BaseRepo;
import com.example.a2205douyin.entity.GiftEntity;
import com.example.a2205douyin.entity.ResultEntity;
import com.example.a2205douyin.entity.VideoEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class LiveRepo extends BaseRepo {
    //关注
    public void guanzhu(RequestBody body, MutableLiveData<ResultEntity> guanSucc,MutableLiveData<String> guanFail){
        apiServer.guanzhu(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        guanSucc.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        guanFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void noguanzhu(RequestBody body, MutableLiveData<ResultEntity> noguanSucc,MutableLiveData<String> noguanFail){
        apiServer.noguanzhu(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        noguanSucc.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        noguanFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void gift(MutableLiveData<GiftEntity> giftSucc,MutableLiveData<String> giftFail){
        apiServer.gift()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GiftEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GiftEntity entity) {
                        giftSucc.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        giftFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void video(int page, int size, MutableLiveData<VideoEntity> videoSuccess, MutableLiveData<String> videoFail){
        apiServer.video(page,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoEntity entity) {
                        videoSuccess.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        videoFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
